<template>
  <el-dialog
    title="重置密码"
    :visible="visible"
    width="30%"
    @close="$emit('onClose')"
  >
    <div>
      <span>
        用户
        <span class="name-str"> {{ modalData.nameStr }}</span>
        的密码被重置为：{{ modalData.newPwd }}
      </span>
      <el-button type="text" @click="onCopy">点击复制</el-button>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="$emit('onClose')">
        知道了
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  props: {
    visible: {
      default: false,
      type: Boolean
    }
  },

  data() {
    return {
      centerDialogVisible: false
    }
  },
  computed: {
    ...mapGetters(['modalData'])
  },
  methods: {
    onCopy() {
      const oInput = document.createElement('input')
      oInput.value = this.modalData.newPwd
      document.body.appendChild(oInput)
      oInput.select() // 选择对象
      document.execCommand('Copy') // 执行浏览器复制命令
      document.body.removeChild(oInput)
    }
  },
}
</script>

<style lang="scss" scoped>
$bg-color: #9580f9;
.name-str {
  color: $bg-color;
}
</style>
